﻿@using Novagoal.Website.Models.Views
@using Novagoal.Website.WebApp.Helpers
@using Novagoal.Utils

@model PlayersViewModel
@{
    ViewBag.Title = string.Format("Novagoal | {0} Player", Model.Player.Id == 0 ? "Add" : "Edit");
    Layout = "~/Views/Shared/MasterLayout.cshtml";
}
@section PageContent {
    <script src="@Url.Content("~/Scripts/novagoal-players.js")" type="text/javascript"></script>
    <div class="main-content ui-corner-top">
        <div class="ui-widget-header ui-corner-all">
            <div class="title">@string.Format("{0} Player", Model.Player.Id == 0 ? "Add" : "Edit")</div>
        </div>

        @{Html.RenderPartial("SubmitResults"); }
        <div class="ui-widget-content ui-corner-bottom">
            @using (Html.BeginForm("Save", "Players", FormMethod.Post, new { id = "playerForm", enctype = "multipart/form-data" }))
            {
                <input type="hidden" id='PlayerId' name='PlayerId' value='@Model.Player.Id' />
                <fieldset class='formContent'>
                <legend>Player Information</legend>
                    <div class='formColumn'>
                        @Html.Label("Name *")
                        @Html.TextBox("Name", Model.Player.Name)
                        <br />
                        @Html.Label("MVP *")
                        @Html.TextBox("Mvp", Model.Player.Mvp)
                    </div>
                    <div class='formColumn'>
                        @Html.Label("Position *")
                        @Html.DropDownList("Position", new SelectList(Enum.GetValues(typeof(Enums.PlayerPositions)), Model.Player.Position))
                    </div>
                </fieldset>
                <br />
                <fieldset>
                <legend>Teams</legend>
                <div>
                    @Html.Label("Add team")
                    @Html.DropDownList("TeamList", new SelectList(Model.Teams, "Id", "Name"), "Select one")
                    <input type="button" onclick="AddTeam()" value="Add" />
                    <table id="TeamsList" class="main-table" style="width:20%">
                        <tr>
                            <th class="ui-widget-header ui-corner-all">Team</th>
                            <th class="ui-widget-header ui-corner-all">Enabled</th>
                        </tr>
                        @foreach (var teamPlayer in Model.PlaysIn)
                        {
                            <tr>
                                <td>
                                    @Html.Hidden("TeamId", teamPlayer.Key.Id)
                                    @teamPlayer.Key.Name
                                </td>
                                <td class="center">
                                    @{
                                        var check = teamPlayer.Value ? "true" : "false"; 
                                        }
                                    @Html.DropDownList("Enabled", new SelectList(new List<string>() { "true", "false" }, check), new { style = "width:50px" })
                                </td>
                            </tr>
                        }
                    </table>
                    </div>
                </fieldset>
                <br />
                <div style='text-align:center'>
                    <input type="submit" value="Save" class='button' />
                </div>
            }
        </div>
    </div>
}
